package com.guxingke.typecho4j.jfinal.handle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.core.JFinal;
import com.jfinal.handler.Handler;

/**
 * 
 * 目的在于让形如：http://xxx:port/yyy/zz的请求url<br/>
 * jfinal没有对应action时，将此请求转发至http://xxx:port /index处理
 * 
 * @author guxingke
 *
 */
public class MyHandle extends Handler {

	@Override
	public void handle(String target, HttpServletRequest request,
			HttpServletResponse response, boolean[] isHandled) {
		if (target.indexOf('.') != -1) {
			return;
		}

		String[] urlPara = { null };

		if (JFinal.me().getAction(target, urlPara) == null) {
			nextHandler.handle("/index", request, response,
					isHandled);
		} else {
			nextHandler.handle(target, request, response, isHandled);
		}
	}

}
